package com.slw.caiji.controller;

import com.slw.caiji.Vo.SysTemplateVo;
import com.slw.caiji.Vo.params.PageParams;
import com.slw.caiji.dto.SysTemplate;
import com.slw.caiji.dto.SysTemplate;
import com.slw.caiji.service.SysTemplateService;
import com.slw.caiji.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/api/template")
@Api(tags = "模板模块管理")
public class SysTemplateController {

    @Autowired
    private SysTemplateService sysTemplateService;

    @PostMapping("list")
    @Operation(summary = "分页获取模板信息列表", description = "分页获取模板信息列表")
    public Result getList(@RequestBody SysTemplateVo sysTemplateVo) {
        return sysTemplateService.getSysTemplateList(sysTemplateVo);
    }

    @PostMapping("add")
    @Operation(summary = "新增模板信息", description = "新增模板信息")
    public Result addTemplate(@RequestBody SysTemplate sysTemplate) {
        return sysTemplateService.addTemplate(sysTemplate);
    }

    @GetMapping("del")
    @Operation(summary = "删除模板信息", description = "删除模板信息")
    public Result delTemplate(@RequestParam String ids) {
        return sysTemplateService.delTemplate(ids);
    }

    @GetMapping("detail")
    @Operation(summary = "模板信息详情接口", description = "获取模板信息详情")
    public Result detailTemplate(@RequestParam String id) {
        return sysTemplateService.detailTemplate(id);
    }

    @PostMapping("update")
    @Operation(summary = "更新模板信息接口", description = "编辑模板信息")
    public Result updateTemplate(@RequestBody SysTemplate sysTemplate) {
        return sysTemplateService.updateTemplate(sysTemplate);
    }

    @PostMapping("import")
    @Operation(summary = "导入模板数据接口", description = "导入模板数据")
    public Result importTemplate(@RequestBody MultipartFile file) throws IOException {
        return sysTemplateService.importTemplate(file);
    }

    @PostMapping("export")
    @Operation(summary = "导出模板信息接口", description = "导出模板数据")
    public void exportTemplate(@RequestBody SysTemplate sysTemplate, HttpServletResponse httpServletResponse) throws IOException {
        sysTemplateService.exportTemplate(sysTemplate, httpServletResponse);
    }
}
